package com.hitqz.robot.schedule;

import com.hitqz.robot.netty.message.ChipMessage;
import com.hitqz.robot.util.ChipToolKit;
import io.netty.channel.ChannelHandlerContext;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author xupkun
 * @date 2024/11/3
 */
@Slf4j
@Component
@AllArgsConstructor
public class ChipSchedule {



    @Scheduled(fixedDelay = 1000)
    public void queryStatus() throws InterruptedException {
        List<String> allId = ChipToolKit.GlobalId;
        for (String id : allId) {
            ChannelHandlerContext ctx = ChipToolKit.findByIpAddress(id);
            if (ctx != null) {
                // 推杆 状态
                ctx.writeAndFlush(new ChipMessage(new byte[] {
                        0x1F, 0x01, 0x09, 0x0B, 0x00, 0x00, 0x00, 0x00
                }));
                Thread.sleep(100);
                // air 
                ctx.writeAndFlush(new ChipMessage(new byte[] {
                        0x2B, 0x02
                }));
            }
        }
    }
}
